package indiwood.controller;

import indiwood.model.MemberVO;
import indiwood.model.ScheduleDateVO;
import indiwood.model.ScheduleTimeVO;
import indiwood.model.SeatVO;
import indiwood.model.ShowingVO;
import indiwood.model.TicketingVO;
import indiwood.model.service.TicketingService;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/ticketing")
public class TicketingController {
	@Resource(name = "ticketingServiceImpl")
	private TicketingService ticketingService;
	
	
	@RequestMapping("/auth_reserve.do")
	public ModelAndView reserve(){
		return new ModelAndView("reserve.ticketing","orderListMap", ticketingService.orderListMap());
	}
	@RequestMapping("/auth_orderList.do")
	public ModelAndView orderList(HttpServletRequest request){
		HttpSession session = request.getSession(false);
		HashMap<String, Object> ticketingMap = new HashMap<String, Object>();
		MemberVO mvo = (MemberVO)session.getAttribute("mvo");
		ticketingMap.put("flag", "N");
		if(mvo!=null){
			List<TicketingVO> ticketingList = ticketingService.getTicketingListByEmail(mvo.getEmail());
			ticketingMap.put("ticketingList", ticketingList);
			if(!ticketingList.isEmpty())
				ticketingMap.put("flag", "Y");
		}
		return new ModelAndView("orderList.ticketing", "ticketingMap", ticketingMap);
	}
	@RequestMapping("/seatList.do")
	public ModelAndView seatList(TicketingVO ticketingVO){
		ScheduleTimeVO allOrder = ticketingService.getAllOrderByTicketingNo(ticketingVO);
		return new ModelAndView("seatList.ticketing", "allOrder", allOrder);
	}
	@RequestMapping("/getCinemaListByMovieNoAjax.do")
	@ResponseBody
	public HashMap<String,Object> getCinemaListByMovieNoAjax(int movieNo){
		return ticketingService.orderListMapByMovieNo(movieNo);
	}
	@RequestMapping("/getMovieListByCinemaNoAjax.do")
	@ResponseBody
	public HashMap<String,Object> getMovieListByCinemaNoAjax(ShowingVO showingVO){
		return ticketingService.orderListMapByCinemaNo(showingVO);
	}
	@RequestMapping("/getRunningTimeListByDateAjax.do")
	@ResponseBody
	public List<ScheduleTimeVO> getRunningTimeListByDateAjax(ScheduleDateVO scheduleDateVO){
		List<ScheduleTimeVO> schedulList = ticketingService.orderScheduleListByNo(scheduleDateVO);
		return schedulList;
	}
	@RequestMapping("/ticketing.do")
	public String ticketing(TicketingVO ticketingVO){
		ticketingService.writeTicketing(ticketingVO);
		return "redirect:orderList.do";
	}
	@RequestMapping("/getSeatInfoListByTimeNoAjax.do")
	@ResponseBody
	public List<SeatVO> getSeatInfoListByTimeNoAjax(int timeNo){
		List<SeatVO> seatInfoList = ticketingService.getSeatInfoList(timeNo);
		return seatInfoList;
	}
}
